package com.imau.common.exception;

import com.imau.common.entity.ResultCode;
import com.imau.common.entity.ResultEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * springMVC->管理
 */
@RestControllerAdvice
public class ProjectExceptionAdvice {

    //异常处理的方法


    @ExceptionHandler({BusinessException.class})
    public ResultEntity doBusinessException(BusinessException ex)
    {
        //1.记录日志
        //2.发消息

        System.out.println("业务异常来了....");
        return  new ResultEntity(false,ex.getCode(),ex.getMessage());
    }

    @ExceptionHandler({SystemException.class})
    public ResultEntity doSystemException(SystemException ex)
    {

        System.out.println("系统异常来了....");
        return  new ResultEntity(false,ex.getCode(),ex.getMessage());
    }

    @ExceptionHandler({Exception.class})
    public ResultEntity doException(Exception ex)
    {

        System.out.println("其他异常来了....");
      ex.printStackTrace();
        return  new ResultEntity(ResultCode.SERVER_ERROR);
    }

}
